﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.UI;
using UnityEngine.EventSystems;

public class StartButton : MonoBehaviour,IPointerDownHandler,IPointerUpHandler
{
    Action m_OnTouch;
    const int NotPointerDownFingerId = -100;
    int m_PointerDownFinger = NotPointerDownFingerId;

    Vector3 m_PointerDownPos;

    // Start is called before the first frame update
    void Start()
    {
        m_OnTouch = GetComponentInParent<MBattleMainUI>().OnClickStart;
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        m_PointerDownFinger = eventData.pointerId;
        m_PointerDownPos = eventData.position;
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        /* if(eventData.pointerId == m_PointerDownFinger)
         {
             if ((m_PointerDownPos - eventData.position).sqrMagnitude > 100)
             {
                 m_OnTouch?.Invoke();
                 GameDebug.LogShowy("TouchStart");
             }
         }

         m_PointerDownFinger = NotPointerDownFingerId;*/
    }


    // Update is called once per frame
    void Update()
    {
        if(m_PointerDownFinger != NotPointerDownFingerId)
        {
            if ((m_PointerDownPos - Input.mousePosition).sqrMagnitude > 100)
            {
                m_OnTouch?.Invoke();
                GameDebug.LogShowy("TouchStart");

                m_PointerDownFinger = NotPointerDownFingerId;
            }
        }
    }
}
